<template>
  <el-card class="box-card" style="overflow:auto">
    <div slot="header" class="clearfix" style="height: 30px">
      <h3 style="float: left">用户管理</h3>
    </div>
    <el-card>
      <el-table
        :data="agentData"
        stripe
        style="width: 100%">
        <el-table-column
          fixed
          prop="agentOpenid"
          label="用户名"
          width="200">
        </el-table-column>
        <el-table-column
          prop="agentName"
          label="用户名称"
          width="200">
        </el-table-column>
        <el-table-column
          prop="agentEmail"
          label="邮箱"
          width="200">
        </el-table-column>
        <el-table-column
          fixed="right"
          label=""
        >
          <template slot-scope="scope" style="">
            <el-button @click="handleClick(scope.row)" type="success" size="small">行为分析</el-button>
            <el-button type="primary" size="small" @click="resetPSW(scope.row)">初始化密码</el-button>
            <el-button type="danger" size="small" @click="deleteAgent(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-pagination
      background
      style="margin-top: 3%"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="10"
      layout="total, sizes, prev, pager, next"
      :total="this.totalElements">
    </el-pagination>
  </el-card>
</template>

<script>
  export default {
    mounted:function () {
      this.getAllAgent();
    },
    methods: {
      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 0
        this.getAllAgent()
      },
      handleCurrentChange(val) {
        this.currentPage = val
        this.getAllAgent()
      },
      handleClick(row) {
        this.$router.push({path:'/agent/analyse',query: {id:row.agentOpenid}})
      },
      deleteAgent(row){
        let that=this
        let url="/api/agent/"+row.agentOpenid
        this.$axios.delete(url).then(successResponse =>{location.reload()}).catch(failResponse =>{})
      },
      resetPSW(row){
        let that=this
        let url="/api/agent/reset/psw/"+row.agentOpenid
        this.$axios.get(url).then(successResponse =>{this.$message.info("密码重置成功")}).catch(failResponse =>{})
      },
      getAllAgent(){
        let that=this
        this.$axios.get('/api/agent/find',{
          params: {
            currentPage: this.currentPage - 1,
            pageSize: this.pageSize
          }}).then(successResponse =>{
          that.agentData=successResponse.data.content
          this.pageSize = successResponse.data.pageable.pageSize
          this.totalElements = successResponse.data.totalElements
        }).catch(failResponse =>{})
      }
    },

    data() {
      return {
        currentPage: 1,
        pageSize: 10,
        totalElements: 0,
        agentData:[],

      }
    }
  }
</script>
<style>
  .box-card1 {
    width: 100%;
    height: 100%;

  }


</style>
